<!--
 * @Description:手动对账
-->
<template>
  <div v-loading="page.bodyLoading" element-loading-text="加载中" element-loading-spinner="el-icon-loading" class="registered-container totalRevenue appMainWarp">
    <el-form :inline="true" :model="searchKey" class="demo-form-inline" @submit.native.prevent>
      <el-form-item label="患者ID:">
        <el-input v-model="searchKey.patient_id" placeholder="请输入患者ID" clearable @keyup.enter.native="onLoad" />
      </el-form-item>
      <el-form-item>
        <el-button type="success" icon="el-icon-key" @click="onLoad">解锁</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="table"
        v-loading="page.tableLoading"
        v-el-height-adaptive-table="{bottomOffset: 90}"
        max-height="500px"
        center
        class="table"
        :data="searchData"
        stripe
        border
      >
        <el-table-column type="index" width="90" label="序号" />
        <el-table-column label="患者id" align="center" prop="patient_id">
          <template slot-scope="scope">{{ scope.row.patient_id||'-' }}</template>
        </el-table-column>
        <el-table-column label="患者姓名" align="center" prop="patient_name">
          <template slot-scope="scope">{{ scope.row.patient_name||'-' }}</template>
        </el-table-column>
        <el-table-column label="处方号" align="center" prop="reg_no">
          <template slot-scope="scope">{{ scope.row.reg_no||'-' }}</template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">{{ scope.row.status===1?'成功':'失败' }}</template>
        </el-table-column>
        <el-table-column label="操作员" align="center" prop="admin_user">
          <template slot-scope="scope">{{ scope.row.admin_user||'-' }}</template>
        </el-table-column>
        <el-table-column label="操作时间" align="center" prop="operation_time">
          <template slot-scope="scope">{{ scope.row.operation_time||'-' }}</template>
        </el-table-column>
      </el-table>
    </template>
    <!-- <el-dialog
      :title="'提示'"
      :visible.sync="unlock.flag"
      width="500px"
    >
      <div style="text-align:center;">确认要解锁患者：<span>张三，处方：XXXXX</span>  吗?<br>此操作不可撤销，请谨慎操作！</div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="unlock.flag = false">取 消</el-button>
        <el-button type="primary" @click="AddandWriteHandle">确 定</el-button>
      </div>
    </el-dialog> -->
    <pagination
      :total="page.totalRow"
      :page.sync="page.currentPage"
      :limit.sync="page.pageSize"
      @pagination="getRegList"
    />
  </div>
</template>

<script>
import elHeightAdaptiveTable from '@/directive/el-table'
import { getRegno, unlockReg, regList } from '@/api/generaLedger/index'
import Pagination from '@/components/Pagination' // 分页
export default {
  name: 'Hand',
  components: {
    Pagination
  },
  directives: { elHeightAdaptiveTable },

  data() {
    return {
      compare_type: '', // 入参
      searchKey: {
        patient_id: ''
      },
      unlock: {
        flag: false,
        regId: '',
        regNo: ''
      },
      searchData: [],
      date_type: '', // 按什么显示
      page: {
        bodyLoading: false,
        tableLoading: false,
        currentPage: 1, // 当前页
        pageSize: 20, // 默认条数
        totalRow: 0, // 总条数
        totalPage: 0 // 总页数
      }
    }
  },

  created() {
  },
  mounted() {
    this.getRegList()
    // this.getConfig()
    // this.onLoad()
  },
  methods: {
    // 查询列表
    onLoad() {
      this.page.currentPage = 1
      this.onSearch()
    },
    onSearch() {
      var params = {}
      var that = this
      params.patientId = that.searchKey.patient_id // 每页展示条数
      that.page.bodyLoading = true
      getRegno(params)
        .then((res) => {
          that.page.bodyLoading = false
          this.$confirm(res.data.describe, '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              var params = res.data
              var that = this
              that.page.bodyLoading = true
              unlockReg(params)
                .then((res) => {
                  that.page.bodyLoading = false
                  that.$message({
                    type: 'success',
                    message: res.msg
                  })
                  this.getRegList()
                  // if (res.data.code === 1) {
                  //   that.refundcont = res.data.refund_status
                  //   that.$message({
                  //     type: 'success',
                  //     message: res.data.msg
                  //   })
                  //   that.onSearch()
                  // } else {
                  //   that.$message({
                  //     type: 'warning',
                  //     message: res.data.msg
                  //   })
                  // }
                })
                .catch(() => {
                  that.page.tableLoading = false
                })
            })
            .catch(() => {
              this.$message({
                type: 'info',
                message: '已取消操作'
              })
            })
        })
        .catch(() => {
          that.page.bodyLoading = false
          that.searchData = []
        })
    },
    // AddandWriteHandle(regId, regNo) {
    //   this.unlock.flag = true
    // },
    getRegList() {
      var params = {}
      var that = this
      params.page = that.page.currentPage // 当前页数
      params.limit = that.page.pageSize // 每页展示条数
      that.page.tableLoading = true
      regList(params)
        .then((res) => {
          that.page.tableLoading = false
          that.searchData = res.data.result
          that.page.totalPage = res.data.pages
          that.page.totalRow = parseInt(res.data.count)
        })
        .catch(() => {
          that.page.tableLoading = false
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.totalRevenue {
  position: relative;
  width: 100%;
  .demo-form-inline {
    .el-button--primary {
      background-color: #579ef8 !important;
      color: #fff !important;
    }
    // .el-button {
    //   background-color: #e8f4ff;
    //   color: #579ef8;
    //   border: 1px solid rgba(87, 158, 248, 1);
    // }
  }
  .abnormal {
    color: red;
    text-decoration: underline;
    cursor: pointer;
  }
  .normal {
    color: rgb(113, 118, 133);
    cursor: pointer;
  }
}
</style>

